/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\141.环形链表.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-04-09 17:32:02
 * @Author: tianyiyi
 * @Copyright: Copyright@tianyiyi
 * @LastEditors: Mr.Tian
 * @LastEditTime: 2021-04-09 17:34:52
 */
/*
 * @lc app=leetcode.cn id=141 lang=cpp
 *
 * [141] 环形链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    bool hasCycle(ListNode *head) {
        if(head == NULL || head->next == NULL)
        {
            return false;
        }

        ListNode* fast = head->next;
        ListNode* slow = head;
        while(fast!=NULL && fast->next != NULL)
        {
            if(slow == fast)
            {
                return true;
            }
        }
        return false;
    }   
};
// @lc code=end

